<template>
  <nm-container>
    <el-form label-width="80px" :inline="true" style="background:white;padding-top:20px">
      <el-form-item label="日期" prop="route_name">
        <el-date-picker v-model="form.busDate" type="date" placeholder="选择日期" format="yyyy-MM-dd" value-format="yyyy-MM-dd"> </el-date-picker>
      </el-form-item>
      <nm-button type="primary" @click="getData" text="查 询" style="margin-left:20px"></nm-button>
      <el-button type="primary" @click="cancellation">报班作废</el-button>
    </el-form>

    <el-table ref="topictable" :max-height="tabheight" :data="getList" border align="center" :header-cell-style="{ 'text-align': 'center', 'font-weight': 'bold', color: '#030202' }" :cell-style="{ 'text-align': 'center' }" style="width: 100%;text-align: center;">
      <el-table-column label="" width="40">
        <template slot-scope="scope">
          <el-radio :label="scope.$index" v-model="radio" @change.native="currentRow(scope.row)" style="color: #fff;padding-left: 5px; "></el-radio>
        </template>
      </el-table-column>
      <el-table-column prop="busNo" label="班次"> </el-table-column>
      <el-table-column prop="station_name" label="站点" width="120"> </el-table-column>
      <el-table-column prop="busTime" label="开点"> </el-table-column>
      <el-table-column prop="grade" label="等级">
        <template slot-scope="scope">
          <span>{{ scope.row.grade ? scope.row.grade : '无' }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="busType" label="车型" width="100"> </el-table-column>
      <el-table-column prop="company" label="公司" width="150"> </el-table-column>
      <el-table-column prop="total_seat" label="座">
        <template slot-scope="scope">
          <span>{{ scope.row.total_seat ? scope.row.total_seat : '无' }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="total_seat" label="定">
        <template slot-scope="scope">
          <span>{{ scope.row.total_seat ? scope.row.total_seat : '无' }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="sold_seat" label="售">
        <template slot-scope="scope">
          <span>{{ scope.row.sold_seat ? scope.row.sold_seat : '无' }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="openOrClose" label="开停">
        <template slot-scope="scope">
          <span>{{ scope.row.openOrClose == true ? '开' : '停' }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="flag" label="标示">
        <template slot-scope="scope">
          <span>{{ scope.row.flag == '1' ? '固定班' : '流水班' }}</span>
        </template>
      </el-table-column>
      <el-table-column prop=" is_overtime" label="加班">
        <template slot-scope="scope">
          <span>{{ scope.row.is_overtime == true ? '是' : '否' }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="miles" label="里程(KM)" width="90"> </el-table-column>
      <!-- <el-table-column prop="lineCode" label="票价"> </el-table-column> -->
      <el-table-column prop="vehicle_id" label="车辆代码">
        <template slot-scope="scope">
          <span>{{ scope.row.vehicle_id ? scope.row.vehicle_id : '无' }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="status" label="状态">
        <template slot-scope="scope">
          <span>{{ scope.row.status == 0 ? '未完成' : scope.row.status == 1 ? '完成' : '作废' }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="licensePlateNo" label="车牌号" width="100"> </el-table-column>
      <el-table-column prop="self_no" label="自编号">
        <template slot-scope="scope">
          <span>{{ scope.row.self_no ? scope.row.self_no : '无' }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column prop="lineCode" label="报班"> </el-table-column> -->
      <el-table-column prop="ModifiedTime" label="修改时间">
        <template slot-scope="scope">
          <span>{{ scope.row.ModifiedTime ? scope.row.ModifiedTime : '无' }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="driver_name" label="司机"> </el-table-column>
      <el-table-column prop="driver_contact" label="电话" width="110"> </el-table-column>
    </el-table>
    <el-pagination @current-change="paginationChange" background layout="prev, pager, next" :total="total" />
  </nm-container>
</template>
<script>
import { mixins } from 'netmodular-ui'
import page from './page'
import cols from './cols'
// import SavePage from '../components/save'
// import detailList from '../components/detailList'

const api = $api.dispatch.vehicle_report

export default {
  name: page.name,
  mixins: [mixins.list],
  // components: { SavePage, detailList },
  data() {
    return {
      radio: '',
      form: {
        busDate: '',
      },
      pageSize: 10,
      pageNum: 1,
      total: 0,
      busNo: '',
      getList: [],
      list: {
        title: page.title,
        cols,
        action: api.query,
        model: {
          /** 线路名称 */
          route_name: '',
        },
      },
      removeAction: api.remove,
      buttons: page.buttons,
      tabheight: 400,
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.tabheight = window.innerHeight - this.$refs.topictable.$el.offsetTop - 150
    })
    this.getTime()
    this.getData()
  },
  methods: {
    //选择报班记录
    currentRow(row) {
      this.busNo = row.busNo
    },
    cancellation() {
      if (this.busNo != '') {
        api.canclereportclass({ busDate: this.form.busDate, busNo: this.busNo }).then((res) => {
          if (res.result == true) {
            this.$message({
              message: res.msg,
              type: 'success',
            })
            this.getData()
          } else {
            this.$message.error(res.msg)
          }
        })
      } else {
        this.$message({
          message: '请选择一条报班记录',
          type: 'warning',
        })
      }
    },
    // 获取当天日期
    getTime() {
      let date = new Date()
      let y = date.getFullYear()
      let m = new Date().getMonth() + 1 < 10 ? '0' + (new Date().getMonth() + 1) : new Date().getMonth() + 1
      let d = date.getDate() < 10 ? '0' + new Date().getDate() : new Date().getDate()
      let isDate = y + '-' + m + '-' + d
      this.form.busDate = isDate
    },
    // 查询
    getData() {
      api.getreportclass({ busDate: this.form.busDate, pageNum: this.pageNum, pageSize: this.pageSize }).then((res) => {
        if (res.reports.length == 0) {
          this.$message({
            message: '未查询到信息',
            type: 'warning',
          })
          this.getList = []
        } else {
          this.total = res.totalItems
          this.getList = res.reports
        }
      })
    },
    // 翻页
    paginationChange(val) {
      this.pageNum = val
      this.getData()
    },
  },
}
</script>
